import Vue from 'vue'

export default {
  /** 获取Loading */
  getLoading () {
    return Vue.prototype.$loading({
      lock: true,
      text: 'Loading',
      spinner: 'el-icon-loading',
      background: 'rgba(0, 0, 0, 0.7)'
    })
  },
  /** 是否正常响应 */
  isResponseNormally (response) {
    if (response === undefined || response === null || response.status !== 200) {
      Vue.prototype.$message.error('系统异常！')
      return false
    }
    if (response.data === undefined || response.data === null) {
      Vue.prototype.$message.error('响应异常！')
      return false
    }
    if (response.data.code !== 0) {
      Vue.prototype.$message.error(response.data.msg)
      return false
    }
    return true
  },
  /** 获取文件名后缀 */
  extractFileSuffix (fileName) {
    if (fileName === undefined || fileName === null || fileName === '') {
      Vue.prototype.$message.error('截取文件后缀异常！[文件名不能为空]')
      return ''
    }
    let index = fileName.lastIndexOf('.')
    if (index === -1) {
      Vue.prototype.$message.error('截取文件后缀异常！[文件名中不存在后缀]')
      return ''
    }
    return fileName.substring(index)
  }
}
